<?php 	

require './pdoconfig.php';

//连接数据库
try {
	$pdo = new PDO(DSN,USER,PASS);
	//设置pdo连接属性
	$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
	$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
	$pdo->setAttribute(PDO::ATTR_AUTOCOMMIT,0);

	$pdo->beginTransaction();

} catch (PDOException $e) {
	echo $e->getMessage();
	exit;
}

//处理数据
try {
	$data=[
		['大aa',0,33],
		['大bb',0,33],
		['大cc',0,33]
	];

	$sql="insert into user (name,sex,age) values( ?, ?, ? )";
	$stmt=$pdo->prepare($sql);

	$count=0;
	$ids=[];
	foreach ($data as $key => $value) {
		$stmt->execute($value);
		$count +=$stmt->rowCount();
		$ids[]=$pdo->lastInsertId();
	}
	echo '共插入'.$count.'条数据<br>';
    var_dump($ids);

    $pdo->commit();
    

	



} catch (PDOException $e) {
	$pdo->rollBack();
	echo $e->getMessage();
	exit;
}
